package handler

import (
	"fmt"
	"github.com/julienschmidt/httprouter"
	"net/http"
	"strconv"
)

type Query struct{
	Page uint64   `json:"page"`
	PageSize uint64   `json:"pageSize"`
	CategoryID uint64 `json:"category"`
}

func parseQuery(r *http.Request) ( query Query ) {

	query.PageSize = DEFAULT_PAGESIZE
	query.Page = 1
	if len(r.Form) > 0  {
		if len(r.Form["page"]) >0  {
			query.Page,_ = strconv.ParseUint(r.Form["page"][0], 10, 64)
		}

		if len(r.Form["pageSize"]) >0 {
			query.PageSize,_ = strconv.ParseUint(r.Form["pageSize"][0], 10, 64)
		}

		if len(r.Form["category"]) > 0 {
			query.CategoryID,_  = strconv.ParseUint(r.Form["category"][0], 10, 64)
		}else {
			query.CategoryID = 0
		}
	}
	return query
}


type Response struct {
	Status    int                    `json:"status"` // always 200
	Code      int                    `json:"code"`
	Body      map[string]interface{} `json:"body"`
	Token     string                 `json:"token"`
	Message   string                 `json:"message"`
	RequestId int                    `json:"requestId"`
	Err       int                    `json:"error"`
}

func (resp Response) Default() Response {
	resp.Status = http.StatusOK
	resp.Code = StatusOK
	resp.Body = make(map[string]interface{})
	resp.Token = ""
	resp.Message = ""
	resp.RequestId = 0
	resp.Err = 0
	return resp
}

func (resp *Response) SetData(interface{}) {

}

func Home(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
	fmt.Fprintln(w, "this is home page")
}
